package com.sumainfor.pc.epc.controller.housekeeper;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.epc.dao.HoDecoratePiMapper;
import com.sumainfor.pc.epc.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.epc.service.HoDecoratePiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 租赁房源连接服务管家新房验收结果页
 * <p>
 *
 * @author: zc
 * @create: 2019-09-12 16:57
 **/
@Controller
@RequestMapping("/housekeeper/HoDecoratePiExt")
public class HoDecoratePiExtController {

     @Autowired
    HoDecoratePiService hoDecoratePiService;

     @Autowired
    HoDecoratePiMapper hoDecoratePiMapper;

     @Autowired
    ZpcMktFeign zpcMktFeign;


     /**
      * 根据房源编号查询新房验收信息
      * @author zhoucong
      * @data 2019/9/21
      * @Param
      * @return
      */
     @ResponseBody
     @GetMapping("/getHoDecoratePiExt")
     public JsonResult getHoDecoratePiExtList( @RequestParam Map<String,Object> params){
         JsonResult result = new JsonResult();
         //查询管家验房列表
         List<Map<String,Object>> epcList=hoDecoratePiMapper.getHoDecoratePiList(params);
         //保存房源编号
         List<String> hIdList=new ArrayList<String>();
         for (Map<String,Object> map: epcList){
             if(map.get("HouId")!=null){
                 hIdList.add(map.get("HouId").toString());
             }
         }
         params.put("hIdList",hIdList);
         //根据房源编号查询房源的信息
         JsonResult marketResut=zpcMktFeign.getHouIdInfoList(params);
         if (marketResut.get("errorCode").toString().equals("0")){
             List<Map<String,Object>> marketList=(List<Map<String,Object>>)marketResut.get("result");
             for (Map<String,Object> map1:epcList){
                 if (map1.get("HouId")!=null){
                     for (Map<String,Object> map2:marketList){
                         if (map2.get("HouId")!=null){
                             if (map1.get("HouId").toString().equals(map2.get("HouId").toString())){
                                 map1.putAll(map2);
                             }
                         }
                     }
                 }

             }
         }
         return result.put(epcList);

     }

}
